package cn.com.roy.thread.t4_1_2.conditiontestmoremethod;

import java.util.concurrent.locks.ReentrantLock;

public class MyService {
    private ReentrantLock lock = new ReentrantLock();
    public void methodA(){
        try {
            lock.lock();
            System.out.println("MethodA begin threadname = " + Thread.currentThread().getName() + " time = " + System.currentTimeMillis() );
            Thread.sleep(5000);
            System.out.println("MethodA end threadname = " + Thread.currentThread().getName() + " time = " + System.currentTimeMillis() );

        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }

    public void methodB(){
        try {
            lock.lock();
            System.out.println("MethodB begin threadname = " + Thread.currentThread().getName() + " time = " + System.currentTimeMillis() );
            Thread.sleep(5000);
            System.out.println("MethodB end threadname = " + Thread.currentThread().getName() + " time = " + System.currentTimeMillis() );

        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }
}
